package com.spring.boot.quartz.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.spring.boot.annotation.DataSourceAnnotation;
import com.spring.boot.quartz.bean.JobAndTriggerBean;
import com.spring.boot.quartz.mapper.JobMapper;
import com.spring.boot.quartz.service.IJobAndTriggerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @program: springboot_vue
 * @description: 定时任务实现类
 * @author: ry
 * @create: 2018-08-16 14:28
 **/
@Transactional
@Service
public class IJobAndTriggerServiceImpl implements IJobAndTriggerService {
    @Autowired
    private JobMapper jobMapper;

    /**
     * 查询定时任务
     * @param datasource
     * @param pageNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    @DataSourceAnnotation
    @Transactional
    @Override
    public PageInfo<JobAndTriggerBean> getJobAndTriggerDetails(String datasource, Integer pageNum, Integer pageSize) throws Exception {
        if (pageNum!=null&&pageSize!=null){
            PageHelper.startPage(pageNum,pageSize);
        }
        List<JobAndTriggerBean> job=jobMapper.findAll();
        for (JobAndTriggerBean jobAndTriggerBean : job) {
            System.out.println(jobAndTriggerBean.getJob_name());
        }
        return new PageInfo<>(job);
    }
}
